package com.atguigu.myssm.listeners;

import com.atguigu.myssm.io.ClassPathXmlApplicationContext;
import com.atguigu.myssm.io.beanFactory;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class ContextLoaderListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
       ServletContext servletContext =  servletContextEvent.getServletContext();

        String path = servletContext.getInitParameter("contextConfigLocation");
        beanFactory beanFactory = new ClassPathXmlApplicationContext(path);

        servletContext.setAttribute("beanFactory",beanFactory);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
